project(inc_parser CXX)

# Basic CMake requirements
cmake_minimum_required(VERSION 2.6)

# Setup general CMake properties
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(INC_PARSER_MAJOR_VERSION 0)
set(INC_PARSER_MINOR_VERSION 1)
set(INC_PARSER_PATCH_VERSION 0)
set(INC_PARSER_VERSION "${INC_PARSER_MAJOR_VERSION}.${INC_PARSER_MINOR_VERSION}.${INC_PARSER_PATCH_VERSION}")

# libinc_parser
set(PARSER_SOURCES
	src/block_node.cpp
	src/block_entry_node.cpp
  src/local_decl_node.cpp
  src/variable_decl_node.cpp
  src/type_node.cpp
  src/vector_type_node.cpp
  src/atomic_type_node.cpp
  src/float_type_node.cpp
  src/int_type_node.cpp
	src/if_statement_node.cpp
	src/statement_node.cpp
	src/mutation_node.cpp
	src/procedure_call_node.cpp
	src/function_call_node.cpp
	src/operation_node.cpp
	src/expression_node.cpp
	src/name_node.cpp
	src/compound_name_node.cpp
	src/indexed_name_node.cpp
	src/scoped_name_node.cpp
	src/dereferenced_name_node.cpp
	src/internal_name_node.cpp
	src/immediate_node.cpp
	src/immediate_number_node.cpp
	src/symbol_node.cpp
	src/label_node.cpp
	src/ws_parser.cpp
	src/parse_tree_node.cpp
  src/source_buffer.cpp)

set(PARSER_PUBLIC_HEADERS
	include/inc/parser/block_node.hpp
	include/inc/parser/block_entry_node.hpp
  include/inc/parser/local_decl_node.hpp
  include/inc/parser/variable_decl_node.hpp
  include/inc/parser/type_node.hpp
  include/inc/parser/vector_type_node.hpp
  include/inc/parser/atomic_type_node.hpp
  include/inc/parser/float_type_node.hpp
  include/inc/parser/int_type_node.hpp
	include/inc/parser/if_statement_node.hpp
	include/inc/parser/statement_node.hpp
	include/inc/parser/mutation_node.hpp
	include/inc/parser/procedure_call_node.hpp
	include/inc/parser/function_call_node.hpp
	include/inc/parser/operation_node.hpp
	include/inc/parser/expression_node.hpp
	include/inc/parser/name_node.hpp
	include/inc/parser/compound_name_node.hpp
	include/inc/parser/indexed_name_node.hpp
	include/inc/parser/scoped_name_node.hpp
	include/inc/parser/dereferenced_name_node.hpp
	include/inc/parser/internal_name_node.hpp
	include/inc/parser/immediate_node.hpp
	include/inc/parser/immediate_number_node.hpp
	include/inc/parser/symbol_node.hpp
	include/inc/parser/label_node.hpp
	include/inc/parser/ws_parser.hpp
	include/inc/parser/parse_tree_node.hpp
  include/inc/parser/source_buffer.hpp
  include/inc/parser/utilities.hpp)

set(PARSER_PRIVATE_HEADERS )

# Setup libraries
find_package(Boost 1.33 REQUIRED regex program_options)

# Setup the build environment
include_directories("${CMAKE_SOURCE_DIR}/include" "${CMAKE_BINARY_DIR}/include")

# Build the inc_parser library
add_library(inc_parser ${PARSER_SOURCES})
target_link_libraries(inc_parser ${Boost_LIBRARIES} "mpfr" "gmp")
set_target_properties(inc_parser PROPERTIES
  VERSION "${INC_PARSER_VERSION}")

#
# Testing
#

find_package(GoogleTest 1.0.0)

# Setup the variables we use below.
set(PARSER_TESTS
  test/ws_parser_test.cpp
  test/label_node_test.cpp
  test/symbol_node_test.cpp
  test/immediate_number_node_test.cpp
  test/immediate_node_test.cpp
  test/internal_name_node_test.cpp
  test/dereferenced_name_node_test.cpp
  test/scoped_name_node_test.cpp
  test/indexed_name_node_test.cpp
  test/compound_name_node_test.cpp
  test/name_node_test.cpp
  test/expression_node_test.cpp
  test/operation_node_test.cpp
  test/function_call_node_test.cpp
  test/procedure_call_node_test.cpp
  test/mutation_node_test.cpp
  test/statement_node_test.cpp
  test/if_statement_node_test.cpp
  test/int_type_node_test.cpp
  test/float_type_node_test.cpp
  test/atomic_type_node_test.cpp
  test/vector_type_node_test.cpp
  test/type_node_test.cpp
  test/variable_decl_node_test.cpp
  test/local_decl_node_test.cpp
  test/block_entry_node_test.cpp
  test/block_node_test.cpp)

if(GTEST_FOUND)
  enable_testing()
  include_directories(${GTEST_INCLUDE_DIRS})
  foreach(TEST ${PARSER_TESTS})
    string(REGEX REPLACE "\\.(cc|cxx|cpp)" "" TEST_NAME ${TEST})
    string(REPLACE "test/" "" TEST_NAME ${TEST_NAME})
    set(TEST_SOURCE ${TEST})
    add_executable(${TEST_NAME} ${TEST_SOURCE})
    set_target_properties(${TEST_NAME} PROPERTIES
      RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test")
    target_link_libraries(${TEST_NAME} inc_parser
      ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
    add_test(${TEST_NAME} test/${TEST_NAME})
  endforeach(TEST)
endif(GTEST_FOUND)

